//package com.situ.blog.filter;
//
//
//
//import com.situ.blog.pojo.entity.User;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
//import java.io.IOException;
//
//
////@WebFilter(filterName = "login", urlPatterns = "/*")
//public class LoginFilter implements Filter {
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//        System.out.println("LoginFilter.init");
//    }
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        System.out.println("LoginFilter.doFilter");
//        HttpServletRequest request = (HttpServletRequest) servletRequest;
//        HttpServletResponse response = (HttpServletResponse) servletResponse;
//
//        String requestURI = request.getRequestURI();
//        System.out.println("requestURI: " + requestURI);
//        String method = request.getParameter("method");
//        if (requestURI.startsWith("/static")
//                || requestURI.equals("/verifyCode")
//                || requestURI.equals("/page/login")
//                || requestURI.equals("/page/register")
//                || requestURI.equals("/page/forget")
//                || requestURI.equals("/user") && "login".equals(method)
//                || requestURI.equals("/user") && "register".equals(method)) {
//            filterChain.doFilter(servletRequest, servletResponse);
//            return;
//        }
//
//        HttpSession session = request.getSession();
//        User user = (User) session.getAttribute("user");
//        if (user == null) {
//            response.sendRedirect("/page/login");
//            return;
//        }
//
//        filterChain.doFilter(servletRequest, servletResponse);
//    }
//
//    @Override
//    public void destroy() {
//        System.out.println("LoginFilter.destroy");
//    }
//}
